1. Technical Field
Example embodiments of the present invention relate in general to a method and apparatus for managing a file system, and more specifically, to a method and apparatus for managing a file system in order to store data in a memory of an embedded system.
2. Related Art
Content stored in a file system that is widely used in various kinds of mobile devices, such as a computer and a smart phone, can be largely classified into data and metadata. Data is content constituting a file, and metadata is additional information about the file, e.g., a file name, access rights, a file modification time, and the locations of chunks constituting the file.
Various kinds of memories may be used for a file system, and a NAND flash memory, among various kinds of memories for a file system, is widely used as a storage device for an embedded system, since it can be manufactured at low cost, has a small size, and is shock-resistant. The NAND flash memory has properties that are significantly different from those of a disk.
A NAND flash memory is constituted with several erase blocks, and each erase block is constituted with several pages. The size of a page may be 2 KB, and an erase block may be constituted with 64 pages corresponding to 128 KB.
A flash memory is capable of reading, writing, and erasing data. Reading/writing is performed in units of pages, and in order to rewrite data on a page on which writing has already been performed, it is needed to all erase an erase block to which the page belongs. Erasing an erase block consumes a longer time than reading/writing. Also, each erase block has a limit to the number of times erasing is allowed, and if an erase block has been erased the maximum number of times, then the erase block can be no longer used. Such a disabled erase block is called a “bad block”. If a bad block appears in a flash memory, the memory can no longer function as a storage device, since it is difficult to process the bad block and an available space of the flash memory is reduced by the size of the bad block. Accordingly, in order to expand the lifespan of a flash memory, a technique for evenly wearing out erase blocks so that bad blocks appear as late as possible is needed. The technique is called “wear-leveling”.
In the case of a flash memory, it is undesirable to rewrite data at a specific location of a file, even when partially correcting data written at the specific location. The reason is because the erase blocks must all be erased and the data rewritten, which takes a long time and significantly deteriorates performance. Also, even in the case of correcting only one page, all the erase blocks must be rewritten, resulting in many erasing operations and reducing the lifespan of the flash memory. Accordingly, it is preferable that the flash memory uses a method of writing corrected data in a different location, not where the original data is located, which is called “out-of-place update”.
Meanwhile, in the case of a disk, in order to correct data located in a specific area, it is only necessary to rewrite corrected data in the corresponding area, not to perform a process of erasing and then rewriting as in a flash memory. That is, a disk allows in-place update.
As such, since a flash memory and a disk have different properties, they use different file systems configured to be suitable to their properties. A representative flash file system for a flash memory is a log-structured file system, such as a journaling flash file system (JFFS2), a yet another flash file system (YAFTS2), and the like.
File systems based on the log-structured file system consider a storage space to be a log. That is, the file systems add data to be recorded in the log whenever receiving the data to be recorded. Data is recorded in units of a predetermined length (for example, in units of pages), and the predetermined length for recording is called a “node”. When data to be recorded is corrected data corresponding to previously written data, that is, when a node exists in a log, another node is added to the log without correcting the written data. In other words, the file systems operate based on out-of-place update.
Accordingly, the log-structured file system has improved writing performance through the out-of-place update, and helps expand the lifespan of a flash memory. However, the previous data remains and occupies a storage space. This storage space should be retrieved to record other data therein. The previous data remaining due to out-of-place update is called “garbage”, and a process of detecting obsolete areas filled with garbage and ensuring available space is called “garbage collection”.
Meanwhile, in the log-structured file system, both data and metadata are recorded in a log in units of nodes. That is, like data, metadata is also scattered and stored. In order to access data of a file, metadata of the file is needed, however, it is difficult to know where the metadata is located since the metadata has been scattered and stored. Accordingly, in order to find the metadata, the entire flash memory should be scanned. However, since it is impossible to scan an entire flash memory whenever metadata is required, the entire area of a flash memory is read and metadata information is configured in the flash memory when the file system is mounted. However, this requires a long mount time and large memory consumption since all metadata should be stored in the flash memory. Furthermore, since the mount time and required memory space increase in proportion to the size of a flash memory, a scalability problem becomes significant as the size of a flash memory increases.
Representative disk file systems include ext2, ext3, and the like, which have been used for a long time in Linux. Since a disk allows in-place update as described above, the structure of a disk file system is different from that of a flash file system. Generally, metadata is stored in a specific head area of a storage space. That is, since the location of metadata in a file is known, metadata can be easily read as necessary. That is, it is unnecessary to maintain all metadata in a flash memory, and accordingly, a disk file system achieves a short mount time and small memory consumption.
Due to these advantages, using a disk file system in a large-scale flash memory can be considered, however, the disk file system also has many problems since it has been designed without considering the properties of the flash memory. That is, the disk file system has low writing performance due to in-place update, and includes no component for processing bad blocks.
As described above, if a disk file system for fixing metadata in a specific area of a storage space is used in a NAND flash memory, there are advantages of a short mount time and small memory consumption are obtained, but there are also disadvantages of the flash memory rapidly wearing out and its writing speed deteriorating.